class Solution {
    /*
        使用递归函数，一直递归到链表的最后一个结点，该结点就是反转后的头结点，记作 retret .
        
    */
    public ListNode reverseList(ListNode head) {
        if(head==null || head.next==null){ // 链表为空 或 链表长度为1；
            return head;
        }
        ListNode tmp = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return tmp;
    }
}
class Solution {
    /*
        迭代
    */
    public ListNode reverseList(ListNode head) {
        if(head==null || head.next==null){
            return head;
        }
        ListNode pre = null;
        while(head!=null){
            ListNode tmp = head.next;
            head.next = pre;
            pre = head;
            head = tmp;
        }
        return pre;
    }
}